Conversation
Adapter methods now receive the full error object instead of just the message string. This allows the SQLite adapter to extract FK column names from error.sql, since SQLite's error message lacks column information. For multi-FK models on SQLite, candidate columns are disambiguated by querying which FK value is actually invalid, with a TOCTOU fallback to the first matching validator.
…complex indexes SQLite includes the index name in error messages for expression indexes (format: UNIQUE constraint failed: index 'name'). Parsing this enables index_name, where, complex index, and scoped index support that was previously thought unsupported.
Each extracted method has a single responsibility: resolving lookup keys from the DB error, and finding the best matching validator with FK disambiguation and TOCTOU fallback.
bbatsov
approved these changes
Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SQLite support is extended to cover db_belongs_to validation and additional validates_db_uniqueness_of options (index_name, where, and complex/composite indexes).
Previously, SQLite's foreign_key_error_column returned a single column, which didn't work for disambiguating multiple db_belongs_to associations. The adapter now extracts all candidate columns from the INSERT SQL, and the Rescuer module iterates over them to find the correct validator — with a TOCTOU fallback for concurrent inserts.
The benchmark configurations are also updated to use DatabaseConfig (from config/database_config.rb) instead of hardcoded connection hashes, matching the convention in spec_helper.rb and Rakefile.